package com.xiaochen.manager.controller;

import com.xiaochen.model.vo.common.Result;
import com.xiaochen.model.vo.common.ResultCodeEnum;
import com.xiaochen.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 本地磁盘存储方案,(不推荐),这边推荐使用阿里云OOS,即AliyunOSSOperator.java这个工具类
 */


@Slf4j
@RestController
public class UploadController {

    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    /**
     * 使用阿里云OOS方案上传文件
     */
    @PostMapping("/upload")
    public Result uplaod(MultipartFile file) throws Exception {
        log.info("上传文件:{}" + file.getOriginalFilename());
        //将文件交给OSS存储管理
        String url = aliyunOSSOperator.upload(file.getBytes(),file.getOriginalFilename());
        log.info("文件上传成功,url:{}",url);
        return Result.build(url, ResultCodeEnum.SUCCESS);
    }
}
